home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Library
/
RoseWare - Network Support Library.iso
/
apidev
/
server.arc
/
CLIENT.C
next >
Wrap
Text File
|
1989-12-06
|
7KB
|
183 lines
client.c
/*------------------------------------------------*
* TLA Client *
* *
* Written by: Stephen T. Bunch *
* API Development *
* *
* Date: July 11, 1989 *
* *
*------------------------------------------------*/
#include <stdio.h>
#define INCL_BASE
#include <os2.h>
#include <nwcalls.h>
#include <malloc.h>
#include "server.h"
#define STACK_SIZE 2000
#define PIPENAME "\\PIPE\\TLAPIPE"
char pipeName[80];
/*--------------------------------------------------------------*/
main(int argc,char *argv[])
{
char fileName[20];
struct COMMBUFFER outBuffer;
char ch;
GetServerName();
do {
PrintMenu();
memset(&outBuffer, 0, sizeof(struct COMMBUFFER));
switch (ch = getche()) {
case '3': /* enter new information from a file */
printf("\n\nEnter filename: ");
gets(fileName);
NewInput(fileName);
break;
case '1': /* search for a single tla */
QueryData(FALSE, &outBuffer);
PrintCommBuffer(&outBuffer);
break;
case '2': /* search for multiple tlas */
QueryData(TRUE, &outBuffer);
break;
}
} while (ch != '4');
}
/*--------------------------------------------------------------*/
PrintMenu()
{
system("cls");
printf("\n\tWelcome to the TLA server");
printf("\n\nSelections are:");
printf("\n\t1) Search for single TLA");
printf("\n\t2) Search for multiple TLAs");
printf("\n\t3) Add new TLAs from a file");
printf("\n\t4) Quit");
printf("\n\n\tEnter selection: ");
}
/*--------------------------------------------------------------*
* GetServerName gets the server name if we are a remote client *
*--------------------------------------------------------------*/
GetServerName()
{
char serverName[20], ch;
printf("Are you a Remote Client (not on same wrkstn as server) ?(Y/N) :");
ch = getche();
if (ch == 'y' || ch == 'Y') {
strcpy(pipeName,"\\\\");
printf("\n\nEnter Server Name :");
gets(serverName);
strcat(pipeName, serverName);
}
strcat(pipeName, PIPENAME);
}
/*-------------------------------------------------------*
* NewInput reads in the new TLAs to add to out database *
*-------------------------------------------------------*/
NewInput(fileName)
char *fileName;
{
struct COMMBUFFER commBuffer, outBuffer;
FILE *finput;
if ((finput = fopen(fileName, "r")) == NULL) {
printf("\nError opening input file.");
exit(0);
}
while (TRUE){
memset(&commBuffer, 0, sizeof(struct COMMBUFFER));
ReadSring(commBuffer.record.tla, TLA_SIZE, finput);
if (strcmp(commBuffer.record.tla, "quit") == 0)
break;
ReadSring(commBuffer.record.expanded, 80, finput);
ReadSring(commBuffer.record.explain, 80, finput);
ReadSring(&commBuffer.record.explain[80], 80, finput);
commBuffer.type |= ADD_TO_LIST;
SendMessage(&commBuffer, &outBuffer);
}
}
/*----------------------------------------------------------*
* ReadString reads an input string from the open file sent *
*----------------------------------------------------------*/
ReadSring(buffer, size, file)
char buffer[];
int size;
FILE *file;
{
int i;
char ch;
for (i=0; i<size-1; i++) {
if ((ch = fgetc(file)) == '\n')
break;
else
buffer[i] = ch;
}
buffer[i] = '\0';
}
/*--------------------------------------------------------------*
* QueryData gets the tla from the user and send in the request *
*--------------------------------------------------------------*/
QueryData(queryMany, outBuffer)
WORD queryMany;
struct COMMBUFFER *outBuffer;
{
struct COMMBUFFER commBuffer;
system("cls");
do {
memset(&commBuffer, 0, sizeof(struct COMMBUFFER));
do {
printf("\nEnter TLA to find (q to quit): ");
gets(commBuffer.record.tla);
} while (strlen(commBuffer.record.tla) < 1);
if (strcmp(commBuffer.record.tla, "q") == 0)
break;
commBuffer.type |= QUERY;
SendMessage(&commBuffer, outBuffer);
if (queryMany)
PrintCommBuffer(outBuffer);
} while (queryMany);
}
/*--------------------------------------------------------------------*
* SendMessage sends the communication buffer over the pipe and reads *
* the response *
*--------------------------------------------------------------------*/
SendMessage(commBuffer, outBuffer)
struct COMMBUFFER *commBuffer, *outBuffer;
{
ULONG timeOut;
USHORT bytesRead, err;
timeOut = 10000L; /* time out after 10 seconds */
do { /* send messages down the pipe */
err = DosCallNmPipe(pipeName, (char *)commBuffer,
(USHORT)sizeof(struct COMMBUFFER), (char *)outBuffer,
(USHORT)sizeof(struct COMMBUFFER), &bytesRead, timeOut);
} while (err == ERROR_PIPE_BUSY);
if (err)
printf("DosCallNmPipe Error : %d", err);
}
/*--------------------------------------------------------------*/
PrintCommBuffer(commBuffer)
struct COMMBUFFER *commBuffer;
{
printf("\n%s : %-60s", commBuffer->record.tla, commBuffer->record.expanded);
printf("\n%-80s ", commBuffer->record.explain);
printf("%-79s ", &(commBuffer->record.explain[80]));
}